/* 右侧展开折叠 */
var box = $('.con-right-list div');
$('#rightBtn').click(function () {
    if ($(this).children("i").hasClass("icon-zhankai")) {
        $(this).children("i").removeClass("icon-zhankai").addClass("icon-shouqi");
        $('.rt-bt1').css({"top": "0px","right": "2px","transition": "0.5s"});
        $('.rt-bt2').css({"top": "37px","right": "46px","transition": "0.5s"});
        $('.rt-bt3').css({"top": "84px","right": "71px","transition": "0.5s"});
        $('.rt-bt4').css({"top": "143px","right": "81px","transition": "0.5s"});
        $('.rt-bt5').css({"top": "205px","right": "74px","transition": "0.5s"});
        $('.rt-bt6').css({"top": "254px","right": "49px","transition": "0.5s"});
        $('.rt-bt7').css({"top": "292px","right": "5px","transition": "0.5s"});
    } else {
        $(this).children("i").removeClass("icon-shouqi").addClass("icon-zhankai");
        $('.rt-bt1').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt2').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt3').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt4').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt5').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt6').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt7').css({"top": "145px","right": "-80px","transition": "0.35s"});
    }
});
/* 右侧功能点击 */
$('.con-right-list a').click(function () {
    var obj = $(this);
    var idx = obj.attr("data-type");
    var twoTc = true;
    if ($(".mapbtn-2").text() == '3D') {
        twoTc = false;
    }

    if (idx != "1") {
        if (obj.parent().hasClass("rt-bt"+idx+"-hover")) {
            // 当前是选中的
            // 取消选择
            obj.parent().removeClass("rt-bt"+idx+"-hover");
            // 改变状态
            $(".con-right-list").attr("data-type","");
            // 取消当前的事件
            if (twoTc) {
                if (idx == "2") {
                    // 定位
                    $('.search-2D').hide();
                } else if (idx == "3") {
                    // 属性查询
                    propertiesQuery(false)
                } else if (idx == "4") {
                    // 透明度
                    $("#tmdAlert").hide();
                } else if (idx == "5") {
                    // 测距
                   celiangjuli(false,'line');
                } else if (idx == "6") {
                    // 测高
                } else if (idx == "7") {
                    // 测面
                   celiangjuli(false,'mian');
                } else {
                    alert("事件绑定失败！");
                }
            } else {
                if (idx == "2") {
                    // 定位
                    $("#conFrame")[0].contentWindow.search(false);
                } else if (idx == "3") {
                    // 属性查询
                    propertiesQuery(false)
                } else if (idx == "4") {
                    // 透明度
                    TouMingDu(false);
                } else if (idx == "5") {
                    // 测距
                    $("#conFrame")[0].contentWindow.clearDis();
                } else if (idx == "6") {
                    // 测高
                    $("#conFrame")[0].contentWindow.clearHei();
                } else if (idx == "7") {
                    // 测面
                    $("#conFrame")[0].contentWindow.clearAre();
                } else {
                    alert("事件绑定失败！");
                }
            }
        } else {
            // 当前没有选中
            // 上一个选中的
            var hoveridx = $(".con-right-list").attr("data-type");
            // 有选中的就取消上一个选择
            if ($(".rt-bt"+hoveridx+"-hover").length > 0) {
                $(".rt-bt" + hoveridx).removeClass("rt-bt"+hoveridx+"-hover");
                //取消上一个的事件
                if (twoTc) {
                    if (hoveridx == "2") {
                        // 定位
                        $('.search-2D').hide();
                    } else if (hoveridx == "3") {
                        // 属性查询
                        propertiesQuery(false)
                    } else if (hoveridx == "4") {
                        // 透明度
                        $("#tmdAlert").hide();
                    } else if (hoveridx == "5") {
                        // 测距
                        celiangjuli(false,'line');
                    } else if (hoveridx == "6") {
                        // 测高
                    } else if (hoveridx == "7") {
                        // 测面
                        celiangjuli(false,'mian');
                    } else {
                        alert("事件绑定失败！");
                    }
                } else {
                    if (hoveridx == "2") {
                        // 定位
                        $("#conFrame")[0].contentWindow.search(false);
                    } else if (hoveridx == "3") {
                        // 属性查询
                        propertiesQuery(false)
                    } else if (hoveridx == "4") {
                        // 透明度
                        TouMingDu(false);
                    } else if (hoveridx == "5") {
                        // 测距
                        $("#conFrame")[0].contentWindow.clearDis();
                    } else if (hoveridx == "6") {
                        // 测高
                        $("#conFrame")[0].contentWindow.clearHei();
                    } else if (hoveridx == "7") {
                        // 测面
                        $("#conFrame")[0].contentWindow.clearAre();
                    } else {
                        alert("事件绑定失败！");
                    }
                }

            }


            // 执行当前的事件
            if (twoTc) {
                if (idx == "2") {
                    // 定位
                    $('.search-2D').show();
                } else if (idx == "3") {
                    // 属性查询
                    propertiesQuery(true)
                } else if (idx == "4") {
                    // 透明度
                    $("#tmdAlert").show();
                } else if (idx == "5") {
                    // 测距
                    celiangjuli(true,'line');
                } else if (idx == "6") {
                    // 测高
                    layer.msg("请切换到三维图层！");
                    return false;
                } else if (idx == "7") {
                    // 测面
                    celiangjuli(true,'mian');
                } else {
                    alert("事件绑定失败！");
                }
            } else {
                if (idx == "2") {
                    // 定位
                    $("#conFrame")[0].contentWindow.search(true);
                } else if (idx == "3") {
                    // 属性查询
                    propertiesQuery(true)
                } else if (idx == "4") {
                    // 透明度
                    TouMingDu(true);
                } else if (idx == "5") {
                    // 测距
                    $("#conFrame")[0].contentWindow.measureDis();
                } else if (idx == "6") {
                    // 测高
                    $("#conFrame")[0].contentWindow.measureHei();
                } else if (idx == "7") {
                    // 测面
                    $("#conFrame")[0].contentWindow.measureAre();
                } else {
                    alert("事件绑定失败！");
                }
            }

            // 选中当前点击的
            obj.parent().addClass("rt-bt"+idx+"-hover");
            // 改变状态
            $(".con-right-list").attr("data-type",idx);
        }
    } else {
        // 全图
        $(".con-right-list").attr("data-type","1");
        if (twoTc) {
            quantu();
        } else {
            $("#conFrame")[0].contentWindow.AllView();
        }
    }
});


/* 收回右侧菜单 */
function rightTake() {
    if ($('#rightBtn').children("i").hasClass("icon-shouqi")) {
        $('#rightBtn').children("i").removeClass("icon-shouqi").addClass("icon-zhankai");
        $('.rt-bt1').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt2').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt3').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt4').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt5').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt6').css({"top": "145px","right": "-80px","transition": "0.35s"});
        $('.rt-bt7').css({"top": "145px","right": "-80px","transition": "0.35s"});
    }
}

/* 图层切换事件 */
$(".right-map").click(function () {
    var obj = $(this);
    if (!obj.hasClass("right-map-hover")) {
        // 执行地图切换
        var thisType = obj.children("span").text();

        if ($(".mapbtn-2").text() == "2D") {
            if (thisType == "矢量") {
                addAMap();
            } else if (thisType == "遥感") {
                addTDTimg();
            } else if (thisType == "倾斜") {
                layer.msg("请切换到三维图层！");
                return false;
            } else if (thisType == "DEM") {
                layer.msg("请切换到三维图层！");
                return false;
            } else {
                alert("图层切换失败！");
            }
        }

        $(".right-map").removeClass("right-map-hover");
        obj.addClass("right-map-hover");
    }
});


/* 单击二三维切换 */
$(".mapbtn-2").click(function () {

    // 重置右侧工具
    var righttype = $(".con-right-list").attr("data-type");
    if (righttype != "" && righttype != "1") {
        $('.con-right-list').children("div").removeClass("rt-bt"+righttype+"-hover");
        //取消上一个的事件
        if ($(this).text() == '2D') {
            if (righttype == "2") {
                // 定位
                $('.search-2D').hide();
            } else if (righttype == "3") {
                // 属性查询
            } else if (righttype == "4") {
                // 透明度
                $("#tmdAlert").hide();
            } else if (righttype == "5") {
                // 测距
               celiangjuli(false,'line');
            } else if (righttype == "6") {
                // 测高
            } else if (righttype == "7") {
                // 测面
               celiangjuli(false,'mian');
            } else {
                alert("事件绑定失败！");
            }
        }
    }

    /* 切换23维时，右侧工具栏自动收回 */
    rightTake();

    if ($(this).text() == '2D') {

        $(window.parent.document).find('#contentIframe').attr('src','../shandong3d/examples/shandong3d.html');


    }
});

/* 单击截图 */
$(".mapbtn-3").click(function () {
    if ($(".mapbtn-2").text() == '2D') {
        mapJiePing2d(true);
    }
});




